var PlayerRating = {
    userId: 0,
    arrPlayers1: [],
    arrPlayers2: [],
    urlRating: '',
    msgBox: '',
    init: function(options){
        this.userId = options.userId;
        this.arrPlayers1 = options.arrPlayers1;
        this.arrPlayers2 = options.arrPlayers2;
        this.urlRating = options.urlRating;
        this.msgBox = options.msgBox;
    },
    changePoint: function(playerId, point, team){
        playerId = parseInt(playerId.replace('player-', ''));
        if (team == 1)
            {this.arrPlayers1[playerId] = parseInt(point);}
        else
            {this.arrPlayers2[playerId] = parseInt(point);}
    },
    rate: function(){
        $.ajax({
            url: this.urlRating,
            type: 'post',
            dataType: 'json',
            data:{userid: this.userId, players1: this.arrPlayers1, players2: this.arrPlayers2},
            beforeSend: function(){
                Lightbox.show(PlayerRating.msgBox, 'Thông báo', 300);
            }
        }).success(function(response){
            if ('undefined' != typeof response){
                var msg = '';
                if(!response.error){
                    msg = 'Đã đánh giá thành công.';
                }
                else{
                    msg = 'Có lỗi xảy ra. Vui lòng thử lại sau.';
                }
                $('#lightbox').find('p b').html(msg);
            }
        }).complete(function(){
            setTimeout(function(){Lightbox.hide()}, 5000);
            setTimeout(function(){window.location.reload()}, 6000);
        }).fail(function(xhr){
            console.log(xhr);
        });
    }
}